<?php
require 'Passport.php';
class AccountController extends ZendX_Controller_Action
{
    public function indexAction ()
    {
        
    }
    
    public function logonAction($username='', $password='')
    {
    	$svc = new App_Service_Jsonp();
    	$res = array();
    	$authAdapter = new Ext_Auth_Adapter_Passport($username, $password);
    	$auth = Zend_Auth::getInstance();
    	$result = $auth->authenticate($authAdapter);
    	if ($result->isValid()) {
            $data = $authAdapter->getResultRowObject();
            $auth->getStorage()->write($data);
            $res['realname'] = $data['name'];
            
        }
        echo $_GET["jsonpcallback"].'('.$svc->JSON(array('result' => $res)).')';
        exit();
    }
    
	public function logoffAction()
	{
		$auth = Zend_Auth::getInstance();
        $auth->clearIdentity();
        exit();
	}
	
	public function getrealnameAction()
	{
		$svc = new App_Service_Jsonp();
    	$res = array();
		$auth = Zend_Auth::getInstance();
		if ($auth->hasIdentity()) {
			$data = $auth->getIdentity();
			$res['realname'] = $data['name'];
		}
		echo $_GET["jsonpcallback"].'('.$svc->JSON(array('result' => $res)).')';
		exit();
	}
}

?>